<script lang="ts" setup>
import type { AirAny } from '@airpower/type/AirType'
import { UserService } from '@/model/personnel/user/UserService'
import { AirAlert } from '@airpower/feedback/AirAlert'
import { AirRouter } from '@airpower/helper/AirRouter'
import { ref } from 'vue'

const isLoading = ref(true)

async function init() {
  const platform = AirRouter.router.currentRoute.value.params.platform.toString()
  const code = AirRouter.router.currentRoute.value.query.code?.toString() || ''
  try {
    await UserService.create(isLoading).thirdBind(platform, code)
  }
  catch (e) {
    await AirAlert.create()
      .hideClose()
      .error((e as AirAny).message, '登录失败')
  }
  await AirAlert.success('绑定第三方账号成功', '绑定成功')
  window.close()
}

init()
</script>

<template>
  <div
    v-loading="isLoading"
    class="callback big-loading"
  />
</template>

<style lang="scss" scoped>
.callback {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: white;
}
</style>
